package mulot;

import level.Plateau;
import level.iMulot;
import level.iTexture;
import level.mulotPerso;
import outils.Direction;
import affichage.fabriqueTexture;

public class MaconBas extends Mulot implements iMulot{
	
	private boolean etatMetier;
	
	public MaconBas(int x, int y, mulotPerso deleg) {
		super(x, y, deleg);
		etatMetier=false;
	}
	
	public MaconBas(iMulot m){
		super(m);
	}
	
	public void deplacer(Plateau p){
		applicationMetier(p);
		super.deplacer(p);
	}
	
	private void applicationMetier(Plateau p){
		int xMax = p.getPlateau().length;
		int yMax = p.getPlateau()[0].length;
		Direction d = getD();
		int x = getX();
		int y = getY();
		
		if(!etatMetier){
			if(y<yMax-1 && p.getPlateau()[x+d.getDx()][y+1].traversable()){
				p.getPlateau()[x][y+1]=fabriqueTexture.fabriquer('#');

				etatMetier=true;
			}
		}
		else{
			if(x>0 && x<xMax && y<yMax-1 && p.getPlateau()[x+d.getDx()][y+1].traversable()){
				p.getPlateau()[x][y+1]=fabriqueTexture.fabriquer('#');
			}
			else{
				getDeleg().changerVersMulot(p);
			}				
		}
	}
	
	public void afficher(iTexture[][] tab){
		int x = getX();
		int y = getY();
		mulotPerso deleg = getDeleg();
		Direction dOld = getdOld();
		tab[x][y] = fabriqueTexture.fabriquer('m',deleg.getI(),dOld);
	} 
	
}
